<template>
  <div class="wrapper border-bottom">
    <swiper>
      <swiper-slide :options="swiperOption"
        v-for="(page, index) in pages"
        :key=index>
        <div class="category-container">
          <div class="category-item"
            v-for="icon in page"
            :key="icon.id">
            <img class="item-img" :src="icon.imgUrl">
            <div class="item-title">{{ icon.title }}</div>
          </div>
        </div>
      </swiper-slide>
     <div class="swiper-pagination"  slot="pagination"></div>
    </swiper>
  </div>
</template>

<script>
export default {
  name: 'HomeIcons',
  props: {
    iconList: Array
  },
  data () {
    return {
      swiperOption: {
        pagination: '.swiper-pagination'
      }
    }
  },
  computed: {
    pages () {
      const pages = []
      let page = []
      for (const icon of this.iconList) {
        page.push(icon)
        if (page.length % 8 === 0) {
          pages.push(page)
          page = []
        }
      }
      if (page) {
        pages.push(page)
      }
      return pages
    }
  }
}
</script>

<style lang="stylus" scoped>
  .wrapper >>> .swiper-pagination-bullet-active
    background #fff
  .wrapper
    width 100%
    height 0
    padding-bottom 46%
    background #fff
    .category-container
      padding-top .1rem
      .category-item
        float left
        width 25%
        text-align center
        padding-top .1rem
        .item-img
          width 1.1rem
          height 1.1rem
        .item-title
          padding-top .1rem
</style>
